<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2023/7/31
 * Time: 4:01 PM
 */

namespace app\common\cachemodel\zlcr3;

use app\common\model\BaseCache;
use think\Db;

class Zlcr3AstrModifyCheck extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zlcr3_astr_modify_check';

    /**
     * 获取当前占星师待审中的数据
     * @param $astrId
     * @return array|string
     */
    public function checkTypeInfo($astrId)
    {
        $checkInfoIds = Db::query(" SELECT MAX(id) as tmp_id FROM wechat_backup_07_18_14_43_00.zlcr3_astr_modify_check where astr_id={$astrId} GROUP BY type");
        $checkingInfo = [
            'nickname' => '',
            'avatar' => '',
            'content' => '',
            'pic_list' => [],
            'media_intro' => [
                'type' => 0,
                'img' => '',
                'url' => '',
                'duration' => 0
            ]
        ];
        if ($checkInfoIds)
        {
            $checkInfoIds = array_column($checkInfoIds, 'tmp_id');
            $checkInfo = (new Zlcr3AstrModifyCheck())->where(['id' => ['in', $checkInfoIds]])->column('extend,status', 'type');
            if (isset($checkInfo[1]['status']) && (int)$checkInfo[1]['status'] === 0)
            {
                $checkExtend = json_decode($checkInfo[1]['extend'], true);
                $checkingInfo['avatar'] = $checkExtend['avatar'];
            }
            if (isset($checkInfo[2]['status']) && (int)$checkInfo[2]['status'] === 0)
            {
                $checkExtend = json_decode($checkInfo[2]['extend'], true);
                $checkingInfo['nickname'] = $checkExtend['nickname'];
            }
            if (isset($checkInfo[3]['status']) && (int)$checkInfo[3]['status'] === 0)
            {
                $checkExtend = json_decode($checkInfo[3]['extend'], true);
                $checkingInfo['content'] = $checkExtend['qualification']['content'];
                $checkingInfo['pic_list'] = $checkExtend['qualification']['pic_list'];
            }
            if (isset($checkInfo[4]['status']) && (int)$checkInfo[4]['status'] === 0)
            {
                $checkExtend = json_decode($checkInfo[4]['extend'], true);
                $checkingInfo['work_intro'] = $checkExtend['work_intro'];
            }
            if (isset($checkInfo[5]['status']) && (int)$checkInfo[5]['status'] === 0)
            {
                $checkExtend = json_decode($checkInfo[5]['extend'], true);
                $checkingInfo['service_time'] = $checkExtend['service_time'];
            }
            if (isset($checkInfo[7]['status']))
            {
                $checkExtend = json_decode($checkInfo[7]['extend'], true);
                $checkingInfo['media_intro'] = $checkExtend['media_intro'];
                $checkingInfo['media_intro']['status'] = $checkInfo[7]['status'];
            }
            if (isset($checkInfo[10]['status']) && (int)$checkInfo[10]['status'] === 0)
            {
                $checkExtend = json_decode($checkInfo[10]['extend'], true);
                $checkingInfo['default_chat'] = $checkExtend['default_chat'];
            }
            if (isset($checkInfo[11]['status']) && (int)$checkInfo[11]['status'] === 0)
            {
                $checkExtend = json_decode($checkInfo[11]['extend'], true);
                $checkingInfo['default_reply'] = $checkExtend['default_reply'];
            }
        }
        return $checkingInfo;
    }
}
